package com.my.wemedia.listener;

import com.alibaba.fastjson.JSON;
import com.my.common.constans.UserAuditiConstans;
import com.my.model.user.pojos.ApUser;
import com.my.model.wemedia.pojos.WmUser;
import com.my.wemedia.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class UserAuditListener {
    @Autowired
    private WmUserService wmUserService;

    @KafkaListener(topics = UserAuditiConstans.USER_AUDIT_TOPIC)
    public void saveWmUser(String message) {
        log.info("自媒体端监听到审核消息，开始保存用户信息...");
        ApUser apUser = JSON.parseObject(message, ApUser.class);

        //设置保存的信息
        WmUser wmUser = new WmUser();
        BeanUtils.copyProperties(apUser,wmUser);
        wmUser.setApUserId(apUser.getId());
        wmUser.setStatus(9);
        wmUser.setCreatedTime(new Date());

        //保存自媒体人信息
        wmUserService.saveWmUser(wmUser);
    }
}
